"use strict";
cc._RF.push(module, 'd32ccVW1KpClr14GgYfy05L', 'peopleArcheryInGamePage');
// scripts/Game/Page/peopleArcheryInGamePage.ts

"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var __generator = (this && this.__generator) || function (thisArg, body) {
    var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
    return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
    function verb(n) { return function (v) { return step([n, v]); }; }
    function step(op) {
        if (f) throw new TypeError("Generator is already executing.");
        while (_) try {
            if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
            if (y = 0, t) op = [op[0] & 2, t.value];
            switch (op[0]) {
                case 0: case 1: t = op; break;
                case 4: _.label++; return { value: op[1], done: false };
                case 5: _.label++; y = op[1]; op = [0]; continue;
                case 7: op = _.ops.pop(); _.trys.pop(); continue;
                default:
                    if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
                    if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
                    if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
                    if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
                    if (t[2]) _.ops.pop();
                    _.trys.pop(); continue;
            }
            op = body.call(thisArg, _);
        } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
        if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
    }
};
Object.defineProperty(exports, "__esModule", { value: true });
var gameEngine_1 = require("../../engines/gameEngine");
var CsvFileKind_1 = require("../../engines/libs/CsvFileKind");
var Enum_1 = require("../Enum");
var MainRoot_1 = require("../MainRoot");
var InGamePage_1 = require("./InGamePage");
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
var peopleArcheryInGamePage = /** @class */ (function (_super) {
    __extends(peopleArcheryInGamePage, _super);
    function peopleArcheryInGamePage() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.lb_atkAddition = null;
        _this.lb_schedule = null;
        _this.titleNode = null;
        _this.weaponItem = null;
        _this.weaponContent = null;
        _this.canSynthSpf = null;
        _this.noSynthSpf = null;
        _this.level = null;
        return _this;
    }
    peopleArcheryInGamePage.prototype.start = function () {
        var _this = this;
        this.scheduleOnce(function () {
            cc.tween(_this.titleNode).to(1, { opacity: 0 }).start();
        }, 3);
        this.tipBtn.active = false;
        this.tipsShow.string = this.tipsShow.string.replace("x", (gameEngine_1.default.getManagers().peopleArcheryManager.getData().curInfinityLevel + 1).toString());
    };
    peopleArcheryInGamePage.prototype.bindLevel = function (level) {
        this.level = level;
        this.refrenshAdditionLb();
    };
    peopleArcheryInGamePage.prototype.refrenshAdditionLb = function () {
        var _a;
        var atkAddition = ((_a = this === null || this === void 0 ? void 0 : this.level) === null || _a === void 0 ? void 0 : _a.peopleArcheryData["video_atk_num"]) || 0;
        this.lb_atkAddition.string = "+" + atkAddition;
    };
    peopleArcheryInGamePage.prototype.onBtnAtkAddition = function () {
        var _this = this;
        gameEngine_1.default.getManagers().soundMgr.playSound("mainSound/anNiu");
        if (gameEngine_1.default.getServices().userSrv.getCoins() > 0) {
            gameEngine_1.default.getServices().userSrv.setCoins(-1, true);
            var atkAddition = this.level.role.atk;
            this.level.parseDataAddPeople({ param_type: "1", option_param: atkAddition });
        }
        else {
            gameEngine_1.default.getServices().miniGameSrv.getAppApiInstance().loadAndShowVideoAd(function () {
                var atkAddition = _this.level.role.atk;
                _this.level.parseDataAddPeople({ param_type: "1", option_param: atkAddition });
            }, function () {
            }, null, "看广告加双倍攻击");
        }
    };
    peopleArcheryInGamePage.prototype.onBtnHpAddition = function () {
        var _this = this;
        gameEngine_1.default.getManagers().soundMgr.playSound("mainSound/anNiu");
        if (gameEngine_1.default.getServices().userSrv.getCoins() > 0) {
            gameEngine_1.default.getServices().userSrv.setCoins(-1, true);
            var hpAddition = this.level.role.hp;
            var maxHpAddition = this.level.role.maxHp;
            this.level.role.maxHp = maxHpAddition * 2;
            this.level.role.hp = hpAddition * 2;
            this.level.roleAddParamLb({ param_type: "0", option_param: hpAddition, additionFlag: false });
        }
        else {
            gameEngine_1.default.getServices().miniGameSrv.getAppApiInstance().loadAndShowVideoAd(function () {
                var hpAddition = _this.level.role.hp;
                var maxHpAddition = _this.level.role.maxHp;
                _this.level.role.maxHp = maxHpAddition * 2;
                _this.level.role.hp = hpAddition * 2;
                _this.level.roleAddParamLb({ param_type: "0", option_param: hpAddition, additionFlag: false });
            }, function () {
            }, null, "看广告加双倍血量");
        }
    };
    peopleArcheryInGamePage.prototype.onBtnExit = function () {
        return __awaiter(this, void 0, void 0, function () {
            var Prams, page;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        gameEngine_1.default.getManagers().soundMgr.playSound("mainSound/anNiu");
                        Prams = {
                            mode: this.m_mode,
                        };
                        return [4 /*yield*/, MainRoot_1.default.UISystem.OpenPage(Enum_1.PAGE.PEOPLE_ARCHERY_EXIT_PAGE, Prams)];
                    case 1:
                        page = _a.sent();
                        page.bindLevel(this.level);
                        return [2 /*return*/];
                }
            });
        });
    };
    peopleArcheryInGamePage.prototype.refrenshScedule = function () {
        this.lb_schedule.string = this.level ? (this.level.curWave / this.level.maxWave * 100).toFixed(1) + "%" : "0%";
    };
    peopleArcheryInGamePage.prototype.update = function (dt) {
        this.refrenshScedule();
    };
    peopleArcheryInGamePage.prototype.refrenshWeaponContent = function () {
        var _this = this;
        var weapons = this.level.role.getWeapons();
        var noRepeatAry = [];
        for (var _i = 0, weapons_1 = weapons; _i < weapons_1.length; _i++) {
            var weapon = weapons_1[_i];
            if (!noRepeatAry.includes(weapon)) {
                noRepeatAry.push(weapon);
            }
        }
        var needCount = noRepeatAry.length - this.weaponContent.childrenCount;
        for (var i = 0; i < needCount; i++) {
            var item = cc.instantiate(this.weaponItem);
            item.active = true;
            item.setParent(this.weaponContent);
            item.setPosition(cc.v2(0, 0));
        }
        var numAry = new Array(noRepeatAry.length).fill(0);
        weapons.forEach(function (weaponId) {
            var index = noRepeatAry.indexOf(weaponId);
            if (index != -1) {
                numAry[index]++;
            }
        });
        this.weaponContent.children.forEach(function (item, index) {
            // let lbWeaponName:cc.Label = item.getChildByName("lbName").getComponent(cc.Label);
            var weaponData = gameEngine_1.default.getManagers().csvDataManager.getCsvDataItem(CsvFileKind_1.CsvFileKind.CsvFile.peopleArcheryMagicWeapon, noRepeatAry[index]);
            var iconPath = weaponData["icon_path"];
            var sp = item.getChildByName("icon").getComponent(cc.Sprite);
            MainRoot_1.default.LevelSystem.getOneTypeBundle(_this.level.getLevelInfo().levelType).load("selectWeapon/" + iconPath, cc.SpriteFrame, function (err, spf) {
                if (err) {
                    console.log("加载道具icon失败", err);
                    return;
                }
                sp.spriteFrame = spf;
            });
            var bgSp = item.getChildByName("bg").getComponent(cc.Sprite);
            bgSp.spriteFrame = weaponData["arise_flag"] == "0" ? _this.canSynthSpf : _this.noSynthSpf;
            var effectNode = item.getChildByName("effect");
            effectNode.active = weaponData["arise_flag"] == "0";
            // let tween = cc.tween(effectNode).to(5,{angle:360}).call(()=>{
            //     effectNode.angle = 0;
            // });
            // cc.tween(effectNode).repeatForever(tween).start();
            // lbWeaponName.string = name;
            var lbWeaponNum = item.getChildByName("lbNum").getComponent(cc.Label);
            lbWeaponNum.string = "\u00D7" + numAry[index];
        });
    };
    __decorate([
        property({ type: cc.Label, tooltip: "加攻击按钮" })
    ], peopleArcheryInGamePage.prototype, "lb_atkAddition", void 0);
    __decorate([
        property({ type: cc.Label, tooltip: "进度文本" })
    ], peopleArcheryInGamePage.prototype, "lb_schedule", void 0);
    __decorate([
        property({ type: cc.Node, tooltip: "titleNode" })
    ], peopleArcheryInGamePage.prototype, "titleNode", void 0);
    __decorate([
        property({ type: cc.Node, tooltip: "武器item" })
    ], peopleArcheryInGamePage.prototype, "weaponItem", void 0);
    __decorate([
        property({ type: cc.Node, tooltip: "武器content" })
    ], peopleArcheryInGamePage.prototype, "weaponContent", void 0);
    __decorate([
        property({ type: cc.Node, tooltip: "可以合成的背景图片" })
    ], peopleArcheryInGamePage.prototype, "canSynthSpf", void 0);
    __decorate([
        property({ type: cc.Node, tooltip: "不可以合成的背景图片" })
    ], peopleArcheryInGamePage.prototype, "noSynthSpf", void 0);
    peopleArcheryInGamePage = __decorate([
        ccclass
    ], peopleArcheryInGamePage);
    return peopleArcheryInGamePage;
}(InGamePage_1.default));
exports.default = peopleArcheryInGamePage;

cc._RF.pop();